<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        let fn1 = function () { };//匿名函数
        let fn2 = () => { };//箭头函数
        let fn3 = x => { };//单参数可以省略参数列表扩喊
        let fn4 = x => console.log(x);//单参数可以省略参数列表扩喊
        let fn5 = x => x + 10;//可以省略大括号和return
        let person = {
            name: "张三",
            showName: function () {
                console.log(this) //  这里的this是person
                console.log(this.name)
            },
            viewName: () => {
                console.log(this) //  这里的this是window
                console.log(this.name)
            }
        }
        person.showName()
        person.viewName()

        function Counter() {
            this.count = 0;
            setInterval(() => {
                // 这里的 this 是上一层作用域中的 this，即 Counter实例化对象
                this.count++;
                console.log(this.count);
            }, 1000);
        }
        let counter = new Counter();
    </script>
</head>

<body>

</body>

</html>